package com.hpch.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpch.business.mapper.ClassifyMapper;
import com.hpch.business.service.ClassifyService;
import com.hpch.business.entity.Classify;
import com.hpch.business.param.ClassifyParam;
import com.hpch.common.core.web.PageParam;
import com.hpch.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 网站资讯分类Service实现
 *
 * @author EleAdmin
 * @since 2025-03-02 19:12:18
 */
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> implements ClassifyService {

    @Override
    public PageResult<Classify> pageRel(ClassifyParam param) {
        PageParam<Classify, ClassifyParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<Classify> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<Classify> listRel(ClassifyParam param) {
        List<Classify> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<Classify, ClassifyParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public Classify getByIdRel(Integer id) {
        ClassifyParam param = new ClassifyParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
